<!-- 新增合格供应商 -->
<template>
  <el-scrollbar class="form-panel enterprise">
    <el-form :model="params" class="demo-form-inline" ref="params" :rules="rules" label-position="top">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmName')" prop="fullName">
            <el-input v-model="params.fullName" clearable
              :placeholder="$t('supplier.registerAudit.firmNamePlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmEnName')" prop="fullNameEn">
            <el-input v-model="params.fullNameEn" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.enNamePlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmShortName')" prop="shortName">
            <el-input v-model="params.shortName" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.shortNamePlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmAttribute')" prop="enterpriseAttribute">
            <x-select :placeholder="$t('supplier.registerAudit.attributePlaceholder')"
              v-model="params.enterpriseAttribute" :options="dictOptions['srm_supplier_info.enterprise_attribute']"
              style="width: 100%" />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.allCreditCode')" prop="taxId">
            <el-input v-model="params.taxId" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.codePlaceholder')"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.currency')" prop="registerCapitalCurrency">
            <x-select :placeholder="$t('supplier.registerAudit.currencyPlaceholder')"
              v-model="params.registerCapitalCurrency" :options="dictOptions['currency']" style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.registerCapital')" prop="registerCapital">
            <el-input :placeholder="$t('supplier.registerAudit.capitalPlaceholder')" v-model="params.registerCapital"
              clearable>
              <template slot="append">{{ $t('supplier.registerAudit.tenThousandYuan') }}</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmWebsit')" prop="website">
            <el-input :placeholder="$t('supplier.registerAudit.websitPlaceholder')" v-model="params.website" clearable>
              <template slot="prepend">Http://</template>
              <template slot="append">.com</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmEmail')" prop="email">
            <el-input v-model="params.email" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.emailPlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmPhone')" prop="telephone">
            <el-input v-model="params.telephone" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.phonePlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmFax')" prop="fax">
            <el-input v-model="params.fax" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.faxPlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.staffNumber')" prop="employeeNumber">
            <el-input v-model="params.employeeNumber" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.staffNumberPlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.workersNumber')" prop="technicianNumber">
            <el-input v-model="params.technicianNumber" clearable maxlength="50"
              :placeholder="$t('supplier.registerAudit.workersPlaceholder')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmProperty')" prop="nature">
            <x-select :placeholder="$t('supplier.registerAudit.firmPropertyPlaceholder')" v-model="params.nature"
              :options="dictOptions['srm_supplier_info.nature']" style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.firmType')" prop="enterpriseType">
            <x-select :placeholder="$t('supplier.registerAudit.firmTypePlaceholder')" v-model="params.enterpriseType"
              :options="dictOptions['srm_supplier_info.enterprise_type']" style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.country')" prop="country">
            <x-select ref="countrySelect" :placeholder="$t('supplier.registerAudit.countryPlaceholder')"
              v-model="params.country" :options="dictOptions['country']" :attrOption="{
                label: 'areaName',
                value: 'id'
              }" style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.registeAdrress')" prop="address" :rules="[
            {
              required: params.country === '105807528965108',
              message: $t('supplier.registerAudit.adrressPlaceholder'),
              trigger: 'blur'
            }
          ]">
            <x-address-input :disabled="params.country && params.country !== '105807528965108'"
              :parent-id="params.country" ref="registerTree" :addrType="1"
              :placeholder="$t('supplier.registerAudit.adrressPlaceholder')" v-model="params.address"
              style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item prop="fullAddress" clas="no-label">
            <template #label>&nbsp;&nbsp;</template>
            <el-input v-model="params.fullAddress" :disabled="params.country && params.country !== '105807528965108'"
              :placeholder="$t('supplier.registerAudit.addressInputPlaceholder')" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.economicType')" prop="economicType">
            <x-select :placeholder="$t('supplier.registerAudit.economicTypePlaceholder')" v-model="params.economicType"
              :options="dictOptions['srm_supplier_info.economic_type']" style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.establishmentTime')" prop="birthTime">
            <el-date-picker v-model="params.birthTime" type="date"
              :placeholder="$t('supplier.registerAudit.establishmentTimePlaceholder')" style="width: 100%"
              value-format="yyyy-MM-dd" format="yyyy-MM-dd" default-time="00:00:00" :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.operatingTerm')" prop="operatingPeriod">
            <div class="flex-row">
              <el-date-picker v-model="params.operatingPeriod" :disabled="isLongTerm" type="date"
                :placeholder="$t('supplier.registerAudit.operatingTermPlaceholder')" style="width: 100%"
                value-format="yyyy-MM-dd" format="yyyy-MM-dd" default-time="00:00:00"
                :picker-options="pickerEndOptions">
              </el-date-picker>
              <el-checkbox v-model="isLongTerm" style="margin-left: 10px">{{
                $t('supplier.registerAudit.longTime')
              }}</el-checkbox>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.industryClassification')" prop="industry">
            <x-select-tree v-model="params.industry" ref="selectTree" :is-lazy="true" :nodeKey="'dictCode'"
              :request-url="'/srm/dict/tree/findTree'" :othe-params="{ dictType: 'industry' }"
              :placeholder="$t('supplier.registerAudit.classificationPlaceholder')" :defaultProps="industryProps"
              style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.balanceSheetRatio')" prop="assetLiabilityRatio">
            <el-input v-model="params.assetLiabilityRatio"
              :placeholder="$t('supplier.registerAudit.balanceSheetRatioPlaceholder')" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.rturnOnCapital')" prop="returnOnCapital">
            <el-input v-model="params.returnOnCapital"
              :placeholder="$t('supplier.registerAudit.rturnOnCapitalPlaceholder')" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.mainBusinessSales')" prop="mainBusinessIncome">
            <el-input :placeholder="$t('supplier.registerAudit.mainBusinessSalesPlaceholder')"
              v-model="params.mainBusinessIncome" clearable>
              <template slot="append">{{ $t('supplier.registerAudit.tenThousandYuan') }}</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.totalAssets')" prop="totalAssets">
            <el-input :placeholder="$t('supplier.registerAudit.totalAssetsPlaceholder')" v-model="params.totalAssets"
              clearable>
              <template slot="append">{{ $t('supplier.registerAudit.tenThousandYuan') }}</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.mainType')" prop="mainServeType">
            <x-select-tree :placeholder="$t('supplier.registerAudit.mainTypePlaceholder')"
              v-model="params.mainServeType" :options="dictOptions['main_serve_type']"
              :defaultProps="mainServeTypeProps" style="width: 100%" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('supplier.registerAudit.serviceArea')" prop="mainServeArea" :rules="[
            {
              required: params.country === '105807528965108',
              // required: false,
              message: $t('supplier.registerAudit.serviceAreaPlaceholder'),
              trigger: 'blur'
            }
          ]">
            <x-address-input :disabled="params.country && params.country !== '105807528965108'"
              :parent-id="params.country" ref="serviceTypeTree" :other-params="{
                beginLevel: 1,
                endLevel: 2
              }" :configProps="xAddressConfigProps" :addrType="3"
              :placeholder="$t('supplier.registerAudit.serviceAreaPlaceholder')" v-model="params.mainServeArea"
              style="width: 100%" />
            <!-- <x-address-input
              ref="serviceTypeTree"
              v-model="params.mainServeArea"
              :addrType="3"
              :parent-id="params.country"
              :options="addressOptions"
              :placeholder="$t('supplier.registerAudit.serviceAreaPlaceholder')"
              :configProps="xAddressConfigProps"
            /> -->
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('supplier.registerAudit.customer')" prop="keyCustomers">
            <el-input type="textarea" v-model="params.keyCustomers"
              :placeholder="$t('supplier.registerAudit.customerPlaceholder')" clearable maxlength="200" :autosize="{
                minRows: 3,
                maxRows: 6
              }"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('supplier.registerAudit.mainGoods')" prop="mainProducts">
            <el-input type="textarea" v-model="params.mainProducts"
              :placeholder="$t('supplier.registerAudit.mainGoodsPlaceholder')" clearable maxlength="200" :autosize="{
                minRows: 3,
                maxRows: 6
              }"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('supplier.registerAudit.businessScope')" prop="businessScope">
            <el-input type="textarea" :placeholder="$t('supplier.registerAudit.businessScopePlaceholder')"
              v-model="params.businessScope" style="width: 100%" maxlength="200" :autosize="{
                minRows: 3,
                maxRows: 6
              }"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('supplier.registerAudit.businessLicense')" prop="licenses">
            <template #label>
              <em class="required-icon"> * </em>
              <span>{{ $t('supplier.registerAudit.businessLicense') }}</span>
            </template>
            <!-- 执照上传 -->
            <x-upload ref="businessFileUpload" :edit-flag="true" :limit="1" :fileSize="20"
              :old-file-list="params.licenses || []"
              :file-type="['jpg', 'jpeg', 'png', 'ppt', 'pptx', 'pdf', 'xls', 'xlsx']" :tips="'文件大小不超过20M，文件数量1以内'">
            </x-upload>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('supplier.registerAudit.firmSeal')" prop="seals">
            <!-- 公章上传 -->
            <x-upload ref="sealUpload" :edit-flag="true" :limit="9" :fileSize="20" :old-file-list="params.seals || []"
              :file-type="['jpg', 'jpeg', 'png', 'ppt', 'pptx', 'pdf', 'xls', 'xlsx']">
            </x-upload>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('supplier.registerAudit.whenQualificationLevel')" prop="qualifyFlag">
            <x-radio-group :list-data="dictOptions['system.whether']" v-model="params.qualifyFlag"></x-radio-group>
          </el-form-item>
        </el-col>
        <div v-if="isQualify">
          <el-col :span="8">
            <el-form-item :label="$t('supplier.registerAudit.qualificationCertificate')"
              prop="qualificationCertificate">
              <el-input v-model="params.qualificationCertificate" clearable maxlength="50"
                :placeholder="$t('supplier.registerAudit.qualificationCertificatePlaceholder')"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('supplier.registerAudit.qualificationClass')" prop="qualificationCategory">
              <x-select :placeholder="$t('supplier.registerAudit.qualificationClassPlaceholder')"
                v-model="params.qualificationCategory"
                :options="dictOptions['srm_supplier_info.qualification_category']" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('supplier.registerAudit.QualificationLevel')" prop="qualificationLevel">
              <el-input v-model="params.qualificationLevel"
                :placeholder="$t('supplier.registerAudit.qualificationLevelPlaceholder')" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('supplier.registerAudit.certificationScope')" prop="certificationScope">
              <el-input v-model="params.certificationScope" maxlength="50"
                :placeholder="$t('supplier.registerAudit.certificationScopePlaceholder')" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('supplier.registerAudit.qualificationSubject')" prop="qualificationSubject">
              <el-input v-model="params.qualificationSubject" maxlength="50"
                :placeholder="$t('supplier.registerAudit.qualificationSubjectPlaceholder')" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('supplier.registerAudit.currentlyValid')" prop="currentValidFlag">
              <x-radio-group :list-data="dictOptions['system.whether']"
                v-model="params.currentValidFlag"></x-radio-group>
            </el-form-item>
          </el-col>
        </div>
      </el-row>
    </el-form>
  </el-scrollbar>
</template>
<script>
import {
  omit,
  checkEmail,
  checkMobilePhone,
  checkFloatNumber,
  checkFixPhone,
  checkFixNumber,
  cloneDeep
} from '@package/utils'
import { mapActions, mapState } from 'pinia'
import { apiPostAddBase, apiGetBase, apiPostUpdateBase } from '../api/record'
import { EnumApiCode } from '../../../../../../globalEnum.js'
import { pinias } from '@/common/pinia'

const { recordStore, dictValue } = pinias
export default {
  name: 'EnterpriseInfo',
  props: {
    dictOptions: {
      type: Object,
      default: () => ({})
    },
    supplierId: {
      type: String
    }
  },
  data() {
    return {
      xAddressConfigProps: {
        multiple: true,
        lazy: true
        // checkStrictly: true,
        // expandTrigger: 'click'
      },
      params: {
        fullName: '',
        fullNameEn: '',
        shortName: '',
        enterpriseAttribute: '',
        taxId: '',
        registerCapitalCurrency: '',
        registerCapital: '',
        website: '',
        email: '',
        telephone: '',
        fax: '',
        employeeNumber: '',
        technicianNumber: '',
        country: '',
        fullAddress: '',
        address: [],
        nature: '',
        enterpriseType: '',
        economicType: '',
        birthTime: '',
        operatingPeriod: '',
        industry: {
          dictName: '',
          dictCode: ''
        },
        industryCode: '',
        assetLiabilityRatio: '',
        returnOnCapital: '',
        mainBusinessIncome: '',
        totalAssets: '',
        mainServeType: '',
        mainServeArea: [],
        keyCustomers: '',
        mainProducts: '',
        businessScope: '',
        qualifyFlag: '',
        qualificationCertificate: '',
        qualificationCategory: '',
        qualificationLevel: '',
        certificationScope: '',
        qualificationSubject: '',
        currentValidFlag: '',
        licenses: [],
        seals: []
      },
      rules: {
        fullName: [
          { required: true, message: this.$t('supplier.registerAudit.firmNamePlaceholder'), trigger: 'blur' }
        ],
        enterpriseAttribute: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.attributePlaceholder'),
            trigger: ['blur', 'change']
          }
        ],
        taxId: [{ required: true, message: this.$t('supplier.registerAudit.codePlaceholder'), trigger: 'blur' }],
        registerCapitalCurrency: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.currencyPlaceholder'),
            trigger: ['blur', 'change']
          }
        ],
        registerCapital: [
          { required: true, message: this.$t('supplier.registerAudit.capitalPlaceholder'), trigger: 'blur' },
          { validator: this.validateMoney, trigger: 'blur' }
        ],
        email: [
          { required: true, message: this.$t('supplier.registerAudit.emailPlaceholder'), trigger: 'blur' },
          { validator: this.validateEmail, trigger: 'blur' }
        ],
        telephone: [
          { required: true, message: this.$t('supplier.registerAudit.phonePlaceholder'), trigger: 'blur' },
          { validator: this.validatePhone, trigger: 'blur' }
        ],
        country: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.countryPlaceholder'),
            trigger: ['blur', 'change']
          }
        ],
        address: [
          {
            required: true,
            validator: this.validateAddress
            // trigger: ['blur', 'change']
          }
        ],
        enterpriseType: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.firmTypePlaceholder'),
            trigger: ['blur', 'change']
          }
        ],
        nature: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.firmPropertyPlaceholder'),
            trigger: ['blur', 'change']
          }
        ],
        economicType: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.economicTypePlaceholder'),
            trigger: ['blur', 'change']
          }
        ],
        birthTime: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.establishmentTimePlaceholder'),
            trigger: 'blur'
          }
        ],
        operatingPeriod: [
          {
            required: true,
            validator: this.validateOperating,
            // message: this.$t('supplier.registerAudit.operatingTermPlaceholder'),
            trigger: 'blur'
          }
        ],
        industry: [
          {
            required: true,
            validator: this.validInstry,
            // message: this.$t('certification.enterprise.classificationPlaceholder'),
            trigger: 'blur'
          }
        ],
        // industryClassification: [
        //   { required: true, message: this.$t('supplier.registerAudit.classificationPlaceholder'), trigger: 'blur' }
        // ],
        mainServeType: [
          { required: true, message: this.$t('supplier.registerAudit.mainTypePlaceholder'), trigger: 'blur' }
        ],
        keyCustomers: [
          { required: true, message: this.$t('supplier.registerAudit.customerPlaceholder'), trigger: 'blur' }
        ],
        mainProducts: [
          { required: true, message: this.$t('supplier.registerAudit.mainGoodsPlaceholder'), trigger: 'blur' }
        ],
        businessScope: [
          { required: true, message: this.$t('supplier.registerAudit.businessScopePlaceholder'), trigger: 'blur' }
        ],
        qualifyFlag: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.isQualificationLevelPlaceholder'),
            trigger: 'blur'
          }
        ],
        qualificationCertificate: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.qualificationCertificatePlaceholder'),
            trigger: 'blur'
          }
        ],
        certificationScope: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.certificationScopePlaceholder'),
            trigger: 'blur'
          }
        ],
        qualificationLevel: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.qualificationLevelPlaceholder'),
            trigger: 'blur'
          }
        ],
        qualificationSubject: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.qualificationSubjectPlaceholder'),
            trigger: 'blur'
          }
        ],
        currentValidFlag: [
          {
            required: true,
            message: this.$t('supplier.registerAudit.currentlyValidPlaceholder'),
            trigger: ['blur', 'change']
          }
        ]
      },
      isLongTerm: false,
      pickerOptions: {
        disabledDate: (time) => {
          return new Date(time).getTime() > new Date().getTime() - 86400000
        }
      },
      pickerEndOptions: {
        disabledDate: (time) => {
          return new Date(time).getTime() < new Date().getTime() - 86400000
        }
      },
      industryProps: {
        label: 'dictName',
        value: 'dictCode',
        children: 'children'
      },
      mainServeTypeProps: {
        label: 'supplierTypeName',
        children: 'children'
      }
    }
  },
  watch: {
    supplierId: {
      handler(val) {
        if (this.supplierId) {
          this.getDetail(this.supplierId)
        }
      },
      immediate: true,
      deep: true
    },
    'params.country': {
      // 针对国外的数据，地址数据及主供区域不录入
      handler(val) {
        if (this.params.country !== '105807528965108' && this.params.country) {
          this.params.address = []
          this.params.fullAddress = ''
          this.params.mainServeArea = []
        }
      },
      immediate: true,
      deep: true
    }
  },
  computed: {
    ...mapState(dictValue, ['addressOptions']),
    isQualify() {
      return `${this.params.qualifyFlag}` === '1'
    }
  },
  methods: {
    ...mapActions(recordStore, ['setSupplierId']),
    async getDetail(supplierId) {
      const { data } = await apiGetBase(supplierId)
      this.$nextTick(() => {
        this.params = Object.assign(this.params, cloneDeep(data))
        this.isLongTerm = this.params.operatingPeriod && this.params.operatingPeriod.indexOf('9999') !== -1
        if (this.isLongTerm) {
          this.params.operatingPeriod = ''
        }
        const addressArr = this.params.address
        this.params.mainServeArea = addressArr.filter((v) => {
          return v.addrType === 3
        })
        this.params.address = addressArr.filter((v) => {
          return v.addrType === 1
        })
        this.params.fullAddress = addressArr?.length ? addressArr[0].address : ''
        this.params.qualifyFlag = this.params.qualifyFlag ? `${this.params.qualifyFlag}` : '0'
        this.params.currentValidFlag += ''
        this.params.industry = {
          dictCode: this.params.industryCode,
          dictName: this.params.industryClassification
        }
        this.$emit('getAuditInfo', this.params)
      })
    },
    // 整合注册地址和主供区域地址数据
    getAddressArr() {
      const addressArr = [
        ...this.params.address.map((v) => {
          return {
            ...v,
            address: this.params.fullAddress,
            addrType: 1,
            country: this.$refs.countrySelect.selectionName,
            countryId: this.params.country
          }
        }),
        ...this.params.mainServeArea.map((v) => {
          return {
            ...v,
            addrType: 3,
            country: this.$refs.countrySelect.selectionName,
            countryId: this.params.country
          }
        })
      ]
      return addressArr.filter((v) => Object.keys(v).length > 4)
    },
    // 经营期限数据整合
    getOperatingPeriodTime() {
      let valTimes = ''
      if (this.isLongTerm) {
        valTimes = '9999-12-31 23:59:59'
      } else {
        valTimes = this.params.operatingPeriod ? `${this.params.operatingPeriod} 23:59:59` : ''
      }
      return valTimes
    },
    onSumit(isVaild = true) {
      return new Promise(async (resolve, reject) => {
        const isSubmit = !isVaild || (await this.handleVaildForm())
        if (isSubmit) {
          const licensesFiles = this.$refs.businessFileUpload.fileList
          const sealsFiles = this.$refs.sealUpload.fileList
          const addressArr = this.getAddressArr()
          const _par = {
            ...omit(this.params, ['fullAddress', 'mainServeArea']),
            birthTime: this.params.birthTime ? `${this.params.birthTime} 23:59:59` : '',
            operatingPeriod: this.getOperatingPeriodTime(),
            licenses: licensesFiles?.length
              ? licensesFiles.map((v) => {
                return {
                  fileName: v.name || v.fileName,
                  filePath: v.filePath || v.response.data.filePath,
                  fileType: (v.name || v.fileName).slice((v.name || v.fileName).lastIndexOf('.') + 1),
                  remark: v.remark
                }
              })
              : [],
            seals: sealsFiles?.length
              ? sealsFiles.map((v) => {
                return {
                  fileName: v.name || v.fileName,
                  filePath: v.filePath || v.response.data.filePath,
                  fileType: (v.name || v.fileName).slice((v.name || v.fileName).lastIndexOf('.') + 1),
                  remark: v.remark
                }
              })
              : [],
            address: addressArr,
            industryCode: this.params.industry.dictCode,
            industryClassification: this.params.industry.dictName
          }
          try {
            const { data, code } = 'id' in this.params ? await apiPostUpdateBase(_par) : await apiPostAddBase(_par)
            if (EnumApiCode.Success === code) {
              if (!('id' in this.params)) {
                this.setSupplierId(data)
              }
              // this.getDetail(this.supplierId)
              resolve(data)
            } else {
              reject()
            }
          } finally {
            reject()
          }
        } else {
          reject()
        }
      })
    },
    handleVaildForm() {
      return new Promise((resolve) => {
        this.$refs.params.validate((valid) => {
          if (valid) {
            const licensesFiles = this.$refs.businessFileUpload.fileList
            if (!licensesFiles?.length) {
              this.$message.error(this.$t('supplier.registerAudit.licensePlaceholder'))
              return resolve(false)
            }
            resolve(true)
          } else {
            resolve(false)
          }
        })
      })
    },
    validatePhone(rule, value, callback) {
      if (value && value !== '' && !checkMobilePhone(value) && !checkFixPhone(value)) {
        callback(new Error(this.$t('supplier.registerAudit.pleasePhoneRight')))
      } else {
        callback()
      }
    },
    validateEmail(rule, value, callback) {
      if (value && value !== '' && !checkEmail(value)) {
        callback(new Error(this.$t('supplier.registerAudit.validateEmailRight')))
      } else {
        callback()
      }
    },
    validateMoney(rule, value, callback) {
      if (value && value !== '' && !checkFloatNumber(value)) {
        callback(new Error(this.$t('supplier.registerAudit.validateMoneyRight')))
      } else {
        callback()
      }
    },
    vaildFixNumber(rule, value, callback) {
      if (value && value !== '' && !checkFixNumber(value)) {
        callback(new Error(this.$t('supplier.registerAudit.faxPlaceholder')))
      } else {
        callback()
      }
    },
    validateOperating(rule, value, callback) {
      if (!value && !this.isLongTerm) {
        callback(new Error(this.$t('supplier.registerAudit.operatingTermPlaceholder')))
      } else {
        callback()
      }
    },
    validInstry(rule, value, callback) {
      if (!value.dictCode) {
        callback(new Error(this.$t('supplier.registerAudit.classificationPlaceholder')))
      } else {
        callback()
      }
    },
    validateAddress(rule, value, callback) {
      if (!value.length && !value) {
        callback(new Error(this.$t('supplier.registerAudit.countryPlaceholder')))
      } else {
        callback()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.required-icon {
  margin-right: 4px;
  color: #f56c6c;
}
</style>
